<template>
  <div id="app">
    <nav v-if="isLoggedIn">
      <router-link to="/">首页</router-link> |
      <router-link to="/public-activities">公开活动列表</router-link> |
      <router-link :to="{ name: 'activity-detail', params: { id: 1 } }">公开活动详情</router-link>
      <template v-if="isUserAdmin">
        | <router-link to="/activity-management">活动管理</router-link>
      </template>
      | <a href="#" @click.prevent="logout">退出登录</a>
    </nav>
    <router-view/>
  </div>
</template>

<script>
export default {
  computed: {
    isLoggedIn() {
      return !!localStorage.getItem('userRole');
    },
    isUserAdmin() {
      return localStorage.getItem('userRole') === 'admin';
    }
  },
  methods: {
    logout() {
      localStorage.removeItem('userRole');
      this.$router.push('/login');
    }
  }
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

nav {
  padding: 30px;
}

nav a {
  font-weight: bold;
  color: #2c3e50;
}

nav a.router-link-exact-active {
  color: #42b983;
}
</style>